from .rasterlize import *
from .utils import *
import os.path


def get_rasterlized_cartoon(input_file: str, output_file_name: str, raster_setting=None):
    file_name = os.path.splitext(input_file)[0]
    original_frames = divide_frames(input_file)

    p = len(original_frames)
    if raster_setting is None:
        raster_setting = get_highest_quality(p)
    merged = rasterlize_frames(original_frames, raster_setting)
    merged.save(f"build/merged_{output_file_name}.png")

    rasterlized_frames = generate_rasterlized_cartoon(merged, raster_setting, output_file_name)
    rasterlized_frames[0].save(f"{output_file_name}.gif",
                               save_all=True, append_images=rasterlized_frames[1:], loop=True)
